//
//  pinDaoHeadCell.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/21.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "pinDaoHeadCell.h"
#import "pinDaoModel.h"
#import "goveDetailVC.h"
@implementation pinDaoHeadCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *identifier = @"status";
    
    
    pinDaoHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[pinDaoHeadCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    

    return cell;
}



-(void)setModel:(pinDaoModel *)model{

    _model = model;
    
    [self setCell];

}

-(void)setCell{

    for (int i = 0 ; i < _model.mtArr.count; i++) {
//        NSDictionary * dict = _model.mtArr[i];

        //            创建按钮
        UIButton * button = [[UIButton alloc]init];
        button.width = 90;
        button.height = 35;
        button.x = i%3*100 + 10;
        button.y = i/3*45 + 10;
        button.tag = i;
        button.layer.masksToBounds = YES;
        button.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;

        [button setTintColor:[UIColor blackColor]];
        button.layer.borderWidth = 0.5f;
        button.layer.cornerRadius = 3.0f;
        button.backgroundColor = [UIColor whiteColor];
        [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:button];
        
        
        UILabel * label = [[UILabel alloc]init];
        label.frame = button.frame;
        label.font = [UIFont systemFontOfSize:14.0];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = _model.mtArr[i][@"userName"];
        [self.contentView addSubview:label];
    }

}
-(void)clickButton:(UIButton *)button{

    NSLog(@"clik:%ld",(long)button.tag);
    NSString * userId ;
    NSString * userType ;

    userId = _model.mtArr[button.tag][@"userId"];
    userType = _model.mtArr[button.tag][@"userType"];

    
    //发送一条通知给MainTableViewController
    [[NSNotificationCenter defaultCenter]postNotificationName:@"clicktTuiJian" object:nil userInfo:@{@"userId":userId,@"userType":userType}];
}
@end
